import { reactive } from "vue";
import { page } from "@/api/auth/user";

export const _$ = reactive({
  query: {
    requestParam: {
      pageNum: 0,
      pageSize: 10,
      condition: "",
      userType: "ADMIN",
    },
    responseParam: {
      total: 0,
      records: [],
    },
  },
});

export const $ = {
  onSearch() {
    page(_$.query.requestParam).then((result) => {
      _$.query.responseParam.records.length = 0;
      _$.query.responseParam.records.push(...result.records);
      _$.query.responseParam.total = result.total;
    });
  },

  onReset() {
    _$.query.requestParam = {
      pageNum: 0,
      pageSize: 10,
      condition: "",
      userType: "ADMIN",
    };
    $.onSearch();
  },

  handleSizeChange(val) {
    _$.query.requestParam.pageSize = val;
    $.onSearch();
  },

  handleCurrentChange(val) {
    _$.query.requestParam.pageNum = val;
    $.onSearch();
  },

  clean() {
    _$.query = {
      requestParam: {
        pageNum: 0,
        pageSize: 10,
        condition: "",
        userType: "ADMIN",
      },
      responseParam: {
        total: 0,
        records: [],
      },
    };
    _$.delete = {
      requestParam: {
        ids: [],
        delFlag: "N",
      },
      responseParam: {},
    };
  },
};

export const to = {};
